import os
import constants
from flask import request
from SQLOperation.PatientSQLOperation import PatientSQLOperation
from SQLConfig import app


@app.route('/deletePatient', methods=['Get', 'POST'])
def deletePatient():  # put application's code here
    """
    删除患者
    """
    if request.method == 'POST':
        patientId=request.json.get("patientId")
    elif request.method == 'GET':
        patientId=request.args.get("patientId") 
    patientId=str(patientId)
    if patientId=="116":
        return "can not delete test patient!"
    return deletep(patientId)


def deletep(patientId):
    result = PatientSQLOperation.deleteByid(patientId)
    if (result=="OK"):
        if (patientId is not None and patientId != ""):
            os.popen("rm -rf "+os.path.join(constants.patientBaseUrl,patientId))
    return result